package comxin.demo1.jdbcdemo;

import java.sql.*;

public class jdbcconnection {
    public static void main(String[] args) {

        Driver driver= null;
        Connection conn=null;
        try {
            //DriverManager.registerDriver(new Driver());

            driver = new com.mysql.jdbc.Driver();
            DriverManager.registerDriver(driver);

            String url="jdbc:mysql://localhost:3306/myemployees";
            String username="root";
            String password="root0417";
            conn = DriverManager.getConnection(url, username, password);


            String sql="SELECT * FROM employees WHERE  employee_id=? and ?";
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setInt(1,100);


            ResultSet resultSet = preparedStatement.executeQuery();



            while (resultSet.next()){
                int id=resultSet.getInt(1);
                String string = resultSet.getString(2);
                System.out.println(id);
                System.out.println(string);
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if (conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }

    }

}
